home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / BUS / TMCM Software and Labs.sit / Software for TMCM 7_95 / Files for Lab 10 / Quadratic < prev    next >
Text File  |  1994-05-10  |  1KB  |  45 lines

  1. { This program computes and prints the solutions of the
  2.    equation   A*x^2 + B*x + C = 0, where A, B, and C are
  3.    constants, as given by the quadratic formula. }
  4.  
  5.  
  6. DECLARE A,B,C  { constants in the equation }
  7.  
  8. DECLARE discriminant  { calculated as B^2 - 4*A*C }
  9.  
  10. DECLARE root1, root2  { the two solutions of the equation }
  11.  
  12.  
  13. A := 1       { Set values to be used for these constants in }
  14. B := 1       {    the equations;  these numbers can be changed }
  15. C := -1      {    to find the solutions of any equation. }
  16.  
  17.  
  18. PenUp          { Adjust pen position so text will fit on screen }
  19. moveTo(-8,5)
  20. PenDown
  21.  
  22.  
  23. { describe output to the user }
  24.  
  25. DrawText("The solutions of A*x^2 + B*x + C = 0, where")
  26. DrawText("   A = #A")
  27. DrawText("   B = #B")
  28. DrawText("   C = #C")
  29. DrawText("are:")
  30.  
  31.  
  32. { calculate the solutions }
  33.  
  34. discriminant := B*B - 4*A*C
  35. root1 := (-B - sqrt(discriminant)) / (2*A)
  36. root2 := (-B + sqrt(discriminant)) / (2*A)
  37.  
  38.  
  39. { print the solutions }
  40.  
  41. DrawText("   #root1")
  42. DrawText("and")
  43. DrawText("   #root2")
  44.  
  45.